from fastapi import FastAPI 
from .api.short import router_short 
from .api.user import router_user 


app = FastAPI(title='FastAPI集成超链实战案例')

app.include_router(router=router_user)
app.include_router(router=router_short)


@app.on_event('startup')
async def startup_event():
    from app.db.database import async_engine, Base 
    from .models.model import User, ShortUrl 
    
    async def init_create_table():
        async with async_engine.begin() as conn: 
            await conn.run_sync(Base.metadata.drop_all)
            await conn.run_sync(Base.metadata.create_all)
        
    await init_create_table()


@app.on_event('shutdown')
async def shutdown_event():
    pass 


@app.get('/')
async def login(): 
    return 'qidong'